home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 05 Programming / BFRTH5.DOC < prev    next >
Text File  |  2019-04-13  |  11KB  |  160 lines

  1. *hd3:Blazin' Forth Documentation,SID Support,-#-
  2. *cn1;SID Chip Support*cn0
  3.  
  4. Blazin' Forth Contains all the words necessary to access the SID (Sound Interface Device) of the C64. Forths speed and flexibility make it ideal for this kind of real time control. Included with the source code is an extensive example of using Blazin' Forth to program music. This is loaded by typing: 105 124 THRU . (Remember, you must type MOUNT before using THRU or LOAD. You need only issue MOUNT once, of course. See MOUNT for more information.)
  5.  
  6. MUSIC.ON
  7.  
  8. This word *must* be executed before executing any of the note words. It clears the sound chip, initializes important variables and then starts up a interrupt driven routine that is responsible for timing the voices, and gating off the sounds at the proper time.
  9.  
  10. MUSIC.OFF
  11.  
  12. This word should be at the end of the music program. It restores the 64's normal interrupt system, and shuts off SID. Note that peculiar results will occur if these two words are not used in their proper order. (Note: Typing RUN/STOP RESTORE will have the same effect as MUSIC.OFF)
  13.  
  14. V1 V2 V3
  15. These words set the current voice. For example, typing V1 will cause all of the following commands to affect only voice 1.
  16. *fp0
  17. ATTACK DECAY SUSTAIN RELEASE
  18. These set the envelope parameters for the sid chip. Each one takes a parameter between 0 and 15. Example:
  19.  
  20. V1 0 ATTACK 15 DECAY 0 SUSTAIN 0 RELEASE ( setparams for voice 1)
  21. V2 15 ATTACK 0 DECAY 15 SUSTAIN 15 RELEASE ( setparameters for voice 2)
  22.  
  23.  
  24. VOLUME
  25. Takes a value between 0 and 15. Note that this command sets the volume for all voices.
  26.  
  27. 15 VOLUME ( set volume for all voices to max)
  28.  
  29. C D E F G A B C# D# F# G# A# D< E< F< E# G< A< B< R
  30. These words do the actual playing of the notes. Note that the sign "<" by some of the notes is actually the left arrow sign, but EZ-script won't allow that to be entered into a document. It means the notes are flatted. There is also a word R , which acts like a REST. (TIP: You may find music which has long passages of rests for one voice, while the others continue. It is not necessary to code all of these rests. Once R has been executed, the voice will remain off until it is reactivated with one of the note words. This is a great memory and patience saver. The only thing you must be careful of when coding this way is to make sure the rest specified isn't *longer* than the actual rest, since Blazin' Forth will not play any note before its time.)
  31.  
  32. 1/32 .1/32 1/16 .1/16 1/8 .1/8 1/4 .1/4 1/2 .1/2  WHOLE TRIPLET TIE
  33. These words set the rythmic duration of the note values. Note that you need to set a rythmic value for a particular voice only once - setting other rythmic values for other voices will not affect each other.
  34.  
  35. OC0 OC1 OC2 OC3 OC4 OC5 OC6 OC7
  36. These words set the octaves for each voice. Note that, as for the note length values, once an octave has been set for a voice, it remains set for that voice until you specifically change it - specifying a new octave for a different voice will affect only the new voice, not any of the others. A C64 octave extends from C to B, with OC4 C playing a middle C.
  37.  
  38. TEMPO
  39. This word sets the tempo and the release time (which is a fraction of the tempo) for each note. The tempo value is stored in MAAZEL, while the amount of time the note spends in its release cycle is stored in REL.TIME. (Note for music hackers: You may tweek the value in REL.TIME after you have set it with TEMPO. For example, if you don't wish the note to be gated off at all, you can store a 0 in REL.TIME, while if you would like the notes in the piece to spend more time in the release cycle, you can increase the value stored here by the system.)
  40.  
  41. TRIANGLE SAWTOOTH PULSE NOISE SYNCH RING
  42. These words set the waveform for the current voice. Example:
  43.  
  44. V1 TRIANGLE ( set voice 1 to a triangle wave)
  45. *fp0
  46. PULSE.WIDTH
  47. This word takes a value on the stack, which sets the pulse width for the current voice. (Note that you must have selected the PULSE waveform for this command to have any effect.) This is a number between 0 and 4095. Typing 2048 PULSE.WIDTH will make a square wave.
  48.  
  49. Now that we have covered the basics, here are some examples:
  50.  
  51. MUSIC.ON ( initialize SID and timing routine)
  52. 100 TEMPO   15 VOLUME ( set tempo and volume)
  53. V1 TRIANGLE  0 ATTACK 9 DECAY ( set waveform and envelope for voice 1 )
  54. 1/4 OC4 ( set quarter notes and octave)
  55. C C# D D# E F F# G G# A A# B OC5 C (play a chromatic scale)
  56. MUSIC.OFF ( turn everything off)
  57.  
  58. This is the basic form of all music programs in Blazin' Forth. Note that MUSIC.ON is executed before any paramaters are set, and that the tempo, volume, and note lengths are set before any notes are played.
  59.  
  60. Here is a slightly more complex example. You may enter this interactively, or edit it onto a screen.
  61.  
  62. : SETTINGS ( setup to play some Bach)
  63. 100 TEMPO  15 VOLUME
  64. V1  9 SUSTAIN SAWTOOTH ( voice 1 params)
  65. V2  9 SUSTAIN SAWTOOTH ( voice 2 params) ;
  66.  
  67. : BACH1 ( two part invention# 1, first measure)
  68.  
  69. V1  1/16  OC4  ( voice, duration, octave for voice 1)
  70. R C D E F D E C  1/8  G
  71. V2 1/16 OC3 R C  V1 OC5 C  V2 D E ( play 1/8 notes in V1 against 1/16 in V2)
  72. V1 OC4 B  V2 F D  V1 OC5 C  V2  E C
  73. V1 1/16 D  V2 G  ;
  74.  
  75. Note that it was only necessary to set the octave and duration for each voice once. The system keeps track of the settings for each voice for you, so you only need to change them when the music demands it.
  76. You probably also noticed that I left out the MUSIC.ON  MUSIC.OFF words. That's because we are going to use BACH1 in another word, in just a moment. You can hear the BACH1 word by typing:
  77.  
  78. MUSIC.ON SETTINGS BACH1 MUSIC.OFF
  79.  
  80. or you can make another word:
  81.  
  82. : PLAY-BACH1  MUSIC.ON  SETTINGS BACH1 MUSIC.OFF ;
  83.  
  84. to do the work for you. You can use BACH1 to get almost two measures of this Invention (with slight apologies to JSB) like this:
  85.  
  86. : BACH2   MUSIC.ON  SETTINGS  BACH1 7 TRANSPOSE  BACH1    MUSIC.OFF ;
  87.  
  88. BACH2 will play BACH1 and then repeat it again, a fifth (7 half-steps) higher, which is all Bach really did. Note that we could have easily changed the waveform or the envelope settings for the second measure if we wanted to. The possibilities for programming musical Forth words is limited only by your imagination.
  89.  
  90. Accessing SID's advanced features:
  91.  
  92. Blazin' Forth contains words that make it easy to access the special features of the SID chip, such as the filters.
  93.  
  94. HIPASS LOWPASS BANDPASS NOTCH
  95. These filters specify the type of filter to be used. Note that SID will only allow one type of filter to be selected at once, but this filter will only affect the voices which are routed through it. You may elect to filter all the voices, or only one or two.
  96.  
  97. FILTER
  98. This word routes the current voice through the filter. For example:
  99. V1 LOWPASS FILTER
  100. Will turn on the lowpass filter and route only voice 1 through it. The other voices are un-affected.
  101.  
  102. NOFILTER
  103. This word stops the filtering for the current voice. For example:
  104. V1 NOFILTER
  105. Will restore voice 1 to its un-filtered state. Note that the actual filter setting is unaffected by this command.
  106.  
  107. RESONANCE
  108. This word takes a number between 0 and 15 on the stack, and sets the resonance of the filter, with 15 being maximum resonance. Example:
  109.  
  110. 15 RESONANCE ( set resonance to maximum)
  111. CUTOFF
  112. This word takes a number between 0 and 2047 which sets the cutoff frequency for the current filter.
  113.  
  114. Example:
  115.  
  116. Using our BACH1 example from above, we can play around a little with the filters, to see how they change the sounds that come out:
  117.  
  118. MUSIC.ON  SETTINGS  ( set it up)
  119.  
  120. V1 HIPASS FILTER   2000 CUTOFF 15 RESONANCE ( set up a highpass filter for v1)
  121. BACH1 ( play it)
  122. V2 FILTER  ( filter both voices)
  123. BACH1 ( play it with both filtered voices)
  124. V1 NOFILTER ( don't filter voice 1)
  125. BACH1
  126. V1 LOWPASS FILTER
  127. ( setup a lowpass filter with the same settings, and send v1 thru it)
  128. BACH1 ( play it - note that V2 is still filtered)
  129. V1 NOFILTER V2 NOFILTER BACH1 ( play without filters)
  130. MUSIC.OFF ( shut down everything)
  131.  
  132. As you can see, it is quite easy to access the SID chip using the words provided with the system.
  133.  
  134. MISC.
  135.  
  136. V3OFF
  137. This word will disconnect the audio output of voice 3. It is usually advisable to do this when using the output of voice 3 to modulate the other voices.
  138.  
  139. OSC3@
  140. This word allows you to read the output of the voice 3's oscillator. This can be used to modulate one of the other voices. Note that a waveform must be selected for voice three in order for this register to output anything other than 0.
  141.  
  142. ENV3@
  143. Same as OSC3@ , but allows you to read the value of voice 3's envelope generator. Note that envelope parameters must be set, and voice 3 gated in order for this register to return anything other than 0.
  144.  
  145. TRANSPOSE
  146. Takes a number on the stack, which determines the number of half-steps the following notes will be moved up. Note that only positive values will have any effect. Using TRANSPOSE can save memory (and typing!), since sections which are repeated in a musical work may be replayed in a different key with this word. 0 TRANSPOSE will restore the notes to their normal values.
  147.  
  148. Voice Modulation:
  149. One of the most fascinating areas to explore with SID is the area of voice modulation. In order to modulate voices, it is necessary to modify the source code to some of the sound words in Blazin' Forth. The heart of the music words is a procedure called PLAY. By modifying this word, it is possible to dynamically change the quality of a note while it is actually being sounded, by modulating it or otherwise tampering. There are several examples of how to do this located on the source disk. Note that these screens should be loaded in the order presented below.
  150.  
  151. Screens 125-126 contain a demonstration of how to add vibrato effects. It is possible to vary the width and speed of the vibrato, to get many different types. To access this demo, make sure the disk is available (see MOUNT) and then type: 125 126 THRU . When the screens are compiled, the demo is executed by typing PLAY-LIKE-LYNN .
  152.  
  153. The next 3 screens contain sound effects demonstrations. Screen 127 has the words SIREN and CLAPS. To access these words, type 127 LOAD , and then SIREN or CLAPS .
  154. Screen 128 contains an example of RING MODULATION. Type 128 LOAD and then BELL-SOUNDS.
  155. Screen 129 contains an example of voice synchronization. Type 129 LOAD , and then SYNCH-DEMO.
  156.  
  157. The SID chip is a fascinating device, and the brief discussion here hardly does it credit. It is possible to generate really remarkable music and  sound effects using these words with SID. If you need basic information on things like envelopes, waveforms, and filtering, I would strongly urge you to obtain a copy of the programmers reference quide.
  158. *fp0
  159. *lk:blazin.doc5
  160.